package com.yhsoft.bill.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhsoft.bill.controller.request.*;
import com.yhsoft.bill.controller.response.SalerYfzkOutVo;
import com.yhsoft.bill.controller.response.SysCzMxOutVo;
import com.yhsoft.bill.controller.response.SysXhLogOutVo;
import com.yhsoft.bill.controller.response.SysYfzkOutVo;
import com.yhsoft.bill.service.ISysYfzkMxService;
import com.yhsoft.bill.service.ISysYfzkService;
import com.yhsoft.common.response.PageResult;
import com.yhsoft.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;

/**
 * <p>
 * 平台应付账款 前端控制器
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-11-03
 */
@Api(tags = {"H-财务统计-平台应付账款"})
@RestController
@RequestMapping("/bill/sysYfzk")
public class SysYfzkController {

    @Resource
    private ISysYfzkService iSysYfzkService;

    @Resource
    private ISysYfzkMxService iSysYfzkMxService;



    @ApiOperation("应付账款列表")
    @GetMapping("/getYfzkList")
    public Result<PageResult<SysYfzkOutVo>> getYfzkList(SysYfzkInVo inVo,
                                                        @RequestParam(value = "pageNo") Long pageNo,
                                                        @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SysYfzkOutVo> iPage = iSysYfzkService.getYfzkList(inVo, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("充值")
    @PostMapping("/cz")
    public Result<?> cz(@RequestBody SysCzInVo inVo) {
        String result = iSysYfzkMxService.cz(inVo);
        if (result.equals("success")) {
            iSysYfzkService.cz(inVo);
            return Result.success(result);
        }
        return Result.fail(result);
    }

    @ApiOperation("应付账款详情/充值明细")
    @GetMapping("/getCzMx")
    public Result<PageResult<SysCzMxOutVo>> getCzMx(@Valid SysCzMxInVo inVo,
                                                    @RequestParam(value = "pageNo") Long pageNo,
                                                    @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SysCzMxOutVo> iPage = iSysYfzkMxService.getCzMx(inVo, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("消耗日志")
    @GetMapping("/getXhLog")
    public Result<PageResult<SysXhLogOutVo>> getXhLog(SysYckLogInVo inVo,
                                                      @NotNull(message = "供货商id不能为空！") @RequestParam Integer companyId,
                                                      @RequestParam(value = "pageNo") Long pageNo,
                                                      @RequestParam(value = "pageSize") Long pageSize) {
        IPage<SysXhLogOutVo> iPage = iSysYfzkMxService.getXhLog(inVo, companyId, pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("平台财务统计")
    @GetMapping("/getPtTj")
    public Result<SalerYfzkOutVo> getPtTj() throws IOException {
        SalerYfzkOutVo salerYfzkOutVo = iSysYfzkMxService.getPtTj();
        return Result.success(salerYfzkOutVo);
    }
}
